//
//  TopView.swift
//  kingWeiBo
//
//  Created by King on 15/9/16.
//  Copyright © 2015年 King. All rights reserved.
//

import UIKit
import SDWebImage

class TopView: UIView {
    
    var status:Status?{
    
        didSet{
            if let url = status?.user!.imageUrl{
            
            
                iconView.sd_setImageWithURL(url)
            }
//            iconView.image = UIImage(named: "icon_os7")
            nameLable.text = status?.user?.name
            timeLable.text = "就在刚才"
            souceLable.text = "来自花果山水帘洞"
            vipView.image = status?.user?.renzheng
            memView.image = status?.user?.membRank
        }
    
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.clearColor()
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: - 搭建界面
    func setUpUI(){
        
        let separView = UIView()
        
        separView.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
       
        addSubview(separView)
        addSubview(iconView)
        addSubview(nameLable)
        addSubview(timeLable)
        addSubview(souceLable)
        addSubview(memView)
        addSubview(vipView)
        
        //添加约束
         separView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: separView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        nameLable.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        memView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLable, size: nil, offset: CGPoint(x: 8, y: 0))
        timeLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        souceLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLable, size: nil, offset: CGPoint(x: 8, y: 0))
        vipView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 8))
        
    }

    //MARK: - 懒加载控件
    /// 头像
    private lazy var iconView:UIImageView = UIImageView()
    /// 名称
    private lazy var nameLable:UILabel = UILabel(color: UIColor.blackColor(), fontSize: 15)
    /// 时间
    private lazy var timeLable:UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    /// 来源
    private lazy var souceLable:UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 9)
    ///  是否会员
    private lazy var memView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    /// 是否VIP
    private lazy var vipView:UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
}
